Skip to content

Minor fixes for the AudioController.Update() at 2D Tutorial#89

Merged
ThomasFOG merged 6 commits intoMonoGame:3.8.4from
nahaharo:3.8.4
Aug 13, 2025
Merged

Minor fixes for the AudioController.Update() at 2D Tutorial#89
ThomasFOG merged 6 commits intoMonoGame:3.8.4from
nahaharo:3.8.4

Conversation

@nahaharo
Copy link
Copy Markdown
Contributor

Fix for the MonoGame/MonoGame#8851

This code fixed two things in AudiroController.Update() at 2D game tutorial.

  1. move "_activeSoundEffectInstances.RemoveAt(index)" into if block.
  2. add index++ at the end of while statement.
    public void Update()
    {
        int index = 0;
        while (index < _activeSoundEffectInstances.Count)
        {
            SoundEffectInstance instance = _activeSoundEffectInstances[index];

            if (instance.State == SoundState.Stopped && !instance.IsDisposed)
            {
                instance.Dispose();
                _activeSoundEffectInstances.RemoveAt(index);
            }
            index++;
        }
    }

@nahaharo nahaharo changed the title Add index++ to 2D Tutorial's AudioController.Update() Minor fixes for the AudioController.Update() at 2D Tutorial Jun 20, 2025
@ThomasFOG
Copy link
Copy Markdown

I think it's still a bit broken, see MonoGame/docs.monogame.github.io#148 (comment)

@SimonDarksideJ
Copy link
Copy Markdown
Contributor

Can you review again @nahaharo / @AristurtleDev to ensure the update is the latest?

@nahaharo
Copy link
Copy Markdown
Contributor Author

I think its okay

@AristurtleDev
Copy link
Copy Markdown
Contributor

Sorry for the dealy on checking the changes.

@SimonDarksideJ The code looks good, it implements the reverse loop in each of the chapter sources.

Thanks for the contribution @nahaharo

@ThomasFOG ThomasFOG merged commit 1793359 into MonoGame:3.8.4 Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants